const path = require('path')
const {baseUrl} = require('../config')
const Banner = require('../models/banner');

class HomeCtl {
    async index(ctx) {
        ctx.body = {
            nav_items: [ //小的导航页面
                {
                    img_url: `${baseUrl}/uploads/upload_5ae521c381ae9c9bb5bba653deffd770.png`,
                    label: '大学堂'
                },
                {
                    img_url: `${baseUrl}/uploads/upload_1cde388fcdba7529205b41034f360709.png`,
                    label: '音乐书'
                },
                {
                    img_url: `${baseUrl}/uploads/upload_c3f64e31955d53a521bdb3ed70d7eccd.png`,
                    label: '集市'
                },
                {
                    img_url: `${baseUrl}/uploads/upload_0430ccb9b544f1659b2d312e0d11ca3e.png`,
                    label: '签到'
                }
            ]

        }
    }

    async upload(ctx) {
        const file = ctx.request.files.file
        console.log(file)
        const basename = path.basename(file.path)
        ctx.body = { url: `http://121.199.62.61/uploads/${basename}` }

    }

    async get_banners(ctx) {
        ctx.body = await Banner.find()
    }

    async delete_banner(ctx) {
        ctx.body = await Banner.remove({ _id: ctx.params.id })
    }

    async create_banner(ctx) {
        const banner = await new Banner(ctx.request.body).save();
        ctx.body = banner;
    }

    async hotkey(ctx) {
        ctx.body = [
            {
                id: 100,
                link: 'http://www.baidu.com',
                name: '爱',
                order: 100,
                visible: 100,
            },
            {
                id: 22,
                link: 'http://www.baidu.com',
                name: '作业',
                order: 22,
                visible: 22,
            },
            {
                id: 13,
                link: 'http://www.baidu.com',
                name: '生活',
                order: 13,
                visible: 14,
            },
            {
                id: 12,
                link: 'http://www.baidu.com',
                name: '记录一场美好的旅行',
                order: 12,
                visible: 12,
            }
        ]
    }

    async testMessage(ctx) {
        ctx.body  = [
            {
                "avatar": "http://www.gravatar.com/avatar/d615d5793929e8c7d70eab5f00f7f5f1?s=100&r=x&d=retro",
                "title": "xx评论了你"
            },
            {
                "avatar": "http://www.gravatar.com/avatar/d615d5793929e8c7d70eab5f00f7f5f1?s=100&r=x&d=retro",
                "title": "xx关注了你"
            },
            {
                "avatar": "http://www.gravatar.com/avatar/d615d5793929e8c7d70eab5f00f7f5f1?s=100&r=x&d=retro",
                "title": "xx收藏了你"
            },
            {
                "avatar": "http://www.gravatar.com/avatar/d615d5793929e8c7d70eab5f00f7f5f1?s=100&r=x&d=retro",
                "title": "xx评论了你"
            }
        ]
    }
}


module.exports = new HomeCtl()